package com.ddwl.goods.controller;

import com.ddwl.common.annotation.Auth;
import com.ddwl.common.constant.BaseEnum;
import com.ddwl.common.controller.BaseController;
import com.ddwl.goods.service.ReserveService;
import com.ddwl.schema.bo.base.PageBo;
import com.ddwl.schema.bo.goods.ReserveBo;
import com.ddwl.schema.vo.base.PageVo;
import com.ddwl.schema.vo.base.RestVo;
import com.ddwl.schema.vo.goods.ReserveVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author Fu Zhaohui
 * @version 1.0.0
 * @date 2019/8/15 10:51
 */
@Api(tags = "预约购")
@RequestMapping("reserve")
@RestController
public class ReserveController extends BaseController {

    @Autowired
    private ReserveService reserveService;

    @PostMapping("page")
    @Auth(product = BaseEnum.ProductEnum.CONSOLE)
    @ApiOperation("分页查询预约购")
    public RestVo<PageVo<ReserveVo>> page(@Valid @RequestBody PageBo<ReserveBo> pageBo) {
        return RestVo.ok(reserveService.page(pageBo));
    }

    @PostMapping("/create")
    @Auth
    @ApiOperation("创建预约购")
    public RestVo<String> create(@Valid @RequestBody ReserveBo bo) {
        return RestVo.ok(reserveService.create(bo));
    }

    @PostMapping("/update")
    @Auth
    @ApiOperation("创建预约购")
    public RestVo update(@Valid @RequestBody ReserveBo bo) {
        reserveService.update(bo);
        return RestVo.ok();
    }

    @DeleteMapping("del")
    @Auth
    @ApiOperation("删除预约购")
    public RestVo delete(@RequestParam String id) {
        reserveService.delete(id);
        return RestVo.ok();
    }

    @GetMapping("/detail")
    @Auth
    @ApiOperation("条码搜索预约购")
    public RestVo<ReserveVo> detail(@ApiParam(value = "预约购ID", required = true) @RequestParam String id) {
        return RestVo.ok(reserveService.getById(id));
    }
}
